<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        $this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px } a,a:hover{color:blue;}</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>！</p><br/>版本 V{$Think.version}</div><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_55e75dfae343f5a1"></thinkad><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');

    }
    public function demo(){
    	$demo = array('records'=>array('records'=>'这是一个demo方法'),array('records'=>'这是一个demo1方法'),array('records'=>'这是一个demo2方法'));
    	
    	echo json_encode($demo);
    }

    // 验证码
    public function Verify(){
    	$Verify =     new \Think\Verify();
	    // 验证码字体使用 ThinkPHP/Library/Think/Verify/ttfs/5.ttf
	    $Verify->fontttf = '5.ttf'; 
	    $Verify->entry();
    }
    //banner图
    public function banner(){
        $Banner=M('Banner');
        $info=$Banner->order('banner_id asc')->select();
        echo json_encode($info);
    }
    //分类
    public function group_type(){
        header("content-type:text/html;charset=utf-8");
        $group_type=M('group_type');
        //获取全部数据
        $info=$group_type->order('group_id asc')->select();
        echo json_encode($info);
        //接收分类ID
        $pid=I("get.pid");
        //获取分类数据
        $classify=$group_type->where(array("group_parent_id"=>$pid))->order('group_id asc')->select();//
        echo json_encode($classify);
    }
    public function login(){
        header("content-type:text/html;charset=utf-8");
        $User=M('user');
        $info=$User->select();
        $user_account=I('post.user_account');
        foreach ($info as $key => $value) {
            $tem[$key]=$value['user_account'];
        }
        if(IS_POST){
            $rules = array(
                    array('user_account','require','账号不能为空'),
                    array('user_password','require','密码不能为空'), 
                    array('user_account',$tem,'用户名不存在',2,'in'),
                    );
            if(!$User->validate($rules)->create()){
                $this->error($User->getError(),'',5);
            }else{

                $password=$User->where(array('user_account'=>$user_account))->getField('user_password');
                if($password!=md5(I('post.user_password'))){
                    $this->error('密码不正确','',2);
                }
                session('islogin','1');
                session('username',$username);
                $this->success('登录成功',"http://localhost/tuangouApp/api/index.php/Home/Index/login.html",2);
            }
        }
        $this->display();   
    }
}